home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fips11.zip / SOURCE / LOGDR_ST.H < prev    next >
C/C++ Source or Header  |  1994-05-25  |  5KB  |  142 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module logdr_st.h
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/logdr_st.h 1.1 1994/05/25 22:20:31 schaefer Exp schaefer $
  8.  
  9.     Copyright (C) 1993 Arno Schaefer
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.  
  26.     Report problems and direct all questions to:
  27.  
  28.     schaefer@rbg.informatik.th-darmstadt.de
  29. */
  30.  
  31. #ifndef LOGDR_ST_H
  32. #define LOGDR_ST_H
  33.  
  34. #include "types.h"
  35. #include "disk_io.h"
  36.  
  37. /* ----------------------------------------------------------------------- */
  38. /* Class bootsector - derived from structure sector                        */
  39. /* Must be initialized with pointer to logical drive object                */
  40. /* Read() and write() read/write sector 0 of logical drive                 */
  41. /* ----------------------------------------------------------------------- */
  42.  
  43. class bootsector:public sector
  44. {
  45.     class logical_drive *logical_drive;
  46. public:
  47.     int read (void);
  48.     int write (void);
  49.  
  50.     bootsector (class logical_drive *logical_drive) { bootsector::logical_drive = logical_drive; }
  51. };
  52.  
  53. /* ----------------------------------------------------------------------- */
  54. /* Bios Parameter Block structure                                          */
  55. /* This is not exactly the BPB as understood by DOS, because it contains   */
  56. /* the additional fields that are in the bootsector like jump_instruction, */
  57. /* oem_name etc. Get() extracts info from the bootsector, put() writes the */
  58. /* info back into the bootsector buffer.                                   */
  59. /* ----------------------------------------------------------------------- */
  60.  
  61. struct bios_parameter_block
  62. {
  63.     byte jump_instruction[3];        // EB xx 90 or E9 xx xx
  64.     char oem_name[9];
  65.     word bytes_per_sector;          // usually 512
  66.     byte sectors_per_cluster;       // may differ
  67.     word reserved_sectors;          // usually 1 (bootsector)
  68.     byte no_of_fats;                // usually 2
  69.     word no_of_rootdir_entries;     // usually 512 for HDs (?), 224 for HD-Floppies, 112 for DD-Floppies
  70.     word no_of_sectors;             // 0 on BIGDOS partitions
  71.     byte media_descriptor;          // usually F8h
  72.     word sectors_per_fat;           // depends on partition size
  73.     word sectors_per_track;         // depends on drive
  74.     word drive_heads;               // dto.
  75.     dword hidden_sectors;           // first sector of partition or 0 for FDs
  76.     dword no_of_sectors_long;       // number of sectors on BIGDOS partitions
  77.     byte phys_drive_no;             // 80h or 81h
  78.     byte signature;                 // usually 29h
  79.     dword serial_number;            // random
  80.     char volume_label[12];
  81.     char file_system_id[9];
  82.  
  83.     void get (bootsector *bootsector);
  84.     void put (bootsector *bootsector);
  85. };
  86.  
  87. /* ----------------------------------------------------------------------- */
  88. /* Some miscellaneous figures about the drive                              */
  89. /* Get() extracts this info from the BPB                                   */
  90. /* ----------------------------------------------------------------------- */
  91.  
  92. struct logical_drive_info
  93. {
  94.     dword start_fat1;
  95.     dword start_fat2;
  96.     dword start_rootdir;
  97.     dword start_data;
  98.     dword no_of_clusters;
  99.  
  100.     virtual void get (const bios_parameter_block &bpb);
  101. };
  102.  
  103. /* ----------------------------------------------------------------------- */
  104. /* Abstract Class logical_drive. This can be any DOS drive that allows     */
  105. /* direct reading and writing of sectors, like Harddisk Partitions, Floppy */
  106. /* disks or Ramdisks                                                       */
  107. /* ----------------------------------------------------------------------- */
  108.  
  109. class logical_drive
  110. {
  111.     struct bios_parameter_block pr_bpb;
  112.     struct logical_drive_info pr_info;
  113. public:
  114.     class bootsector *bootsector;
  115.     virtual bios_parameter_block &bpb() { return pr_bpb; }
  116.     virtual logical_drive_info &info() { return pr_info; }
  117.  
  118.     virtual int read_sector (dword number,sector *sector) = 0;
  119.     virtual int write_sector (dword number,sector *sector) = 0;
  120. };
  121.  
  122. /* ----------------------------------------------------------------------- */
  123. /* Function to read bootsector from logical drive                          */
  124. /* It must be in the header file because it is inline                      */
  125. /* ----------------------------------------------------------------------- */
  126.  
  127. inline int bootsector::read (void)
  128. {
  129.     return logical_drive->read_sector (0,this);
  130. }
  131.  
  132. /* ----------------------------------------------------------------------- */
  133. /* Function to write bootsector to logical drive                           */
  134. /* ----------------------------------------------------------------------- */
  135.  
  136. inline int bootsector::write (void)
  137. {
  138.     return logical_drive->write_sector (0,this);
  139. }
  140.  
  141. #endif
  142.